package com.linsir.common.render;

import com.jfinal.kit.PathKit;
import com.jfinal.render.HtmlRender;

import java.util.HashMap;

/**
 * @author yuxiaolin
 * @title: ResourceRender
 * @projectName linsir-mu
 * @description: TODO
 * @date 2021/12/3 11:36 AM
 */

public class ResourceRender extends HtmlRender {

    public ResourceRender(Object object, String view, HashMap<String, Object> attr) {
        super(RenderUtil.renderResource(buildResource(object, view), attr));
    }

    private static String buildResource(Object object, String filePath) {
        // 获取当前方法的上上级 也就是 调用
        // StackTraceElement[] ss = Thread.currentThread().getStackTrace();
        // StackTraceElement a = (StackTraceElement)ss[4];
        // String txt = Utils.readFromResource(filePath);
        String pack = PathKit.getPackagePath(object);
        return String.format("%s/resources/%s", pack, filePath);
    }
}
